package com.qyer.lxp.model.price.normal;

import com.qyer.lxp.common.framework.adapter.DateAdapter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.io.Serializable;
import java.util.Date;

/**
 * 获取销售项目某一天的价格信息接口返回数据类
 * Created by jiangping on 16/5/18.
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Price implements Serializable,Comparable<Price>{

    private static final long serialVersionUID = 3205959562196569741L;

    /**
     * 销售项目 code
     */
    @XmlElement(name = "sale-code")
    private String saleCode;

    /**
     * 规格 id
     */
    @XmlElement(name = "specification-id")
    private String specificationId;

    /**
     * 净价
     */
    @XmlElement(name = "net-price")
    private double netPrice;

    /**
     * 市场价
     */
    @XmlElement(name = "retail-price")
    private double retailPrice;

    /**
     * 服务费
     */
    private double fee;

    /**
     * 最小购买数
     */
    @XmlElement(name = "min-num")
    private int minNum;

    /**
     * 最大购买数
     */
    @XmlElement(name = "max-num")
    private int maxNum;

    /**
     * 配额(-1 表示无限制,0 表示无配额,大于 0 表示配额数)
     */
    private int quota;

    /**
     * 旅行日期
     */
    @XmlJavaTypeAdapter(DateAdapter.class)
    private Date date;

    /**
     * 是否可退
     */
    private boolean cancellable;

    /**
     * 退具体条款描述
     */
    private String cancellation;

    /**
     * 提前申请小时/天数
     */
    @XmlElement(name = "cancel-hours")
    private int cancelHours;

    /**
     * H(小时数)/D(天数)
     */
    @XmlElement(name = "cancel-time-unit")
    private String cancelTimeUnit;

    /**
     * NO_REFUND(不可退订)/PART_REFUND(退订收 费)/RETIRE_REFUND(免费退订)
     */
    @XmlElement(name = "cancel-type")
    private String cancelType;

    /**
     * 更新时间
     * 注:非力行字段
     */
    private Date updateTime;

    /**
     * 创建时间
     * 注:非力行字段
     */
    private Date createTime;

    private int id;

    public String getSaleCode() {
        return saleCode;
    }

    public void setSaleCode(String saleCode) {
        this.saleCode = saleCode;
    }

    public String getSpecificationId() {
        return specificationId;
    }

    public void setSpecificationId(String specificationId) {
        this.specificationId = specificationId;
    }

    public double getNetPrice() {
        return netPrice;
    }

    public void setNetPrice(double netPrice) {
        this.netPrice = netPrice;
    }

    public double getRetailPrice() {
        return retailPrice;
    }

    public void setRetailPrice(double retailPrice) {
        this.retailPrice = retailPrice;
    }

    public double getFee() {
        return fee;
    }

    public void setFee(double fee) {
        this.fee = fee;
    }

    public int getMinNum() {
        return minNum;
    }

    public void setMinNum(int minNum) {
        this.minNum = minNum;
    }

    public int getMaxNum() {
        return maxNum;
    }

    public void setMaxNum(int maxNum) {
        this.maxNum = maxNum;
    }

    public int getQuota() {
        return quota;
    }

    public void setQuota(int quota) {
        this.quota = quota;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public boolean getCancellable() {
        return cancellable;
    }

    public void setCancellable(boolean cancellable) {
        this.cancellable = cancellable;
    }

    public String getCancellation() {
        return cancellation;
    }

    public void setCancellation(String cancellation) {
        this.cancellation = cancellation;
    }

    public int getCancelHours() {
        return cancelHours;
    }

    public void setCancelHours(int cancelHours) {
        this.cancelHours = cancelHours;
    }

    public String getCancelTimeUnit() {
        return cancelTimeUnit;
    }

    public void setCancelTimeUnit(String cancelTimeUnit) {
        this.cancelTimeUnit = cancelTimeUnit;
    }

    public String getCancelType() {
        return cancelType;
    }

    public void setCancelType(String cancelType) {
        this.cancelType = cancelType;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Price{" +
                "saleCode='" + saleCode + '\'' +
                ", specificationId='" + specificationId + '\'' +
                ", netPrice=" + netPrice +
                ", retailPrice=" + retailPrice +
                ", fee=" + fee +
                ", minNum=" + minNum +
                ", maxNum=" + maxNum +
                ", quota=" + quota +
                ", date=" + date +
                ", cancellable=" + cancellable +
                ", cancellation='" + cancellation + '\'' +
                ", cancelHours=" + cancelHours +
                ", cancelTimeUnit='" + cancelTimeUnit + '\'' +
                ", cancelType='" + cancelType + '\'' +
                ", updateTime=" + updateTime +
                ", createTime=" + createTime +
                '}';
    }

    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.
     * <p>
     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
     * <tt>y.compareTo(x)</tt> throws an exception.)
     * <p>
     * <p>The implementor must also ensure that the relation is transitive:
     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
     * <tt>x.compareTo(z)&gt;0</tt>.
     * <p>
     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
     * all <tt>z</tt>.
     * <p>
     * <p>It is strongly recommended, but <i>not</i> strictly required that
     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
     * class that implements the <tt>Comparable</tt> interface and violates
     * this condition should clearly indicate this fact.  The recommended
     * language is "Note: this class has a natural ordering that is
     * inconsistent with equals."
     * <p>
     * <p>In the foregoing description, the notation
     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
     * <i>expression</i> is negative, zero or positive.
     *
     * @param price the object to be compared.
     * @return a negative integer, zero, or a positive integer as this object
     * is less than, equal to, or greater than the specified object.
     * @throws NullPointerException if the specified object is null
     * @throws ClassCastException   if the specified object's type prevents it
     *                              from being compared to this object.
     */
    @Override
    public int compareTo(Price price) {
        int netPrice = Double.compare(this.netPrice,price.getNetPrice());
        if(netPrice != 0){
            return netPrice;
        }
        int retailPrice = Double.compare(this.retailPrice,price.getRetailPrice());
        if(retailPrice != 0){
            return retailPrice;
        }
        int fee = Double.compare(this.fee,price.getFee());
        if(fee != 0)
        {
            return fee;
        }

        return 0;
    }
}
